﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DatabaseCompare.Model
{

    /// <summary>
    /// 数据库 信息
    /// </summary>
    public class DatabaseInfo : CompareAble, ICloneable
    {

        /// <summary>
        /// 数据库中所有的表.
        /// </summary>
        public List<TableInfo> TableList { set; get; }


        /// <summary>
        /// 数据库中所有的视图.
        /// </summary>
        public List<ViewInfo> ViewList { set; get; }


        /// <summary>
        /// 数据库中所有的触发器.
        /// </summary>
        public List<TriggerInfo> TriggerList { set; get; }


        /// <summary>
        /// 数据库中所有的存储过程.
        /// </summary>
        public List<ProcedureInfo> ProcedureList { set; get; }


        /// <summary>
        /// 数据库中所有的函数.
        /// </summary>
        public List<FunctionInfo> FunctionList { set; get; }



        #region ICloneable 成员

        public object Clone()
        {
            // 浅层克隆,
            DatabaseInfo newDatabaseInfo = this.MemberwiseClone() as DatabaseInfo;

            // 重新克隆 表信息.
            if (newDatabaseInfo.TableList != null)
            {

                newDatabaseInfo.TableList = new List<TableInfo>();

                foreach (TableInfo tab in this.TableList)
                {
                    newDatabaseInfo.TableList.Add(tab.Clone() as TableInfo);
                }
            }

            // 返回.
            return newDatabaseInfo;
        }

        #endregion


        public override string ToString()
        {
            StringBuilder buff = new StringBuilder();
            buff.Append("数据库：");

            buff.Append("表List={");
            if (TableList != null)
            {
                buff.AppendLine();
                for (int i = 0; i < TableList.Count; i++)
                {
                    TableInfo table = TableList[i];
                    buff.AppendFormat("  表{0}={1}", i + 1, table);
                    buff.AppendLine();
                }
            }
            buff.Append("}");

            return buff.ToString();
        }
    }

}
